package com.atguigu.lease.common.springmvc;

import com.atguigu.lease.common.exceptions.LeaseException;
import com.atguigu.lease.common.result.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


@RestControllerAdvice
public class GlobalExceptionHandlers {
    @ExceptionHandler(Exception.class)
    public Result exception(Exception e) {
        e.printStackTrace(); //打印异常信息
        return Result.fail();
    }

    @ExceptionHandler(LeaseException.class)
    public Result exception(LeaseException l) {
        l.printStackTrace(); //打印异常信息
        return Result.build(l.getCode(),l.getMessage());
    }

}
